<?php

/**
 * Joomla! 1.5 component arts_curriculum
 * @package    arts_curriculum
 * @subpackage
 * @author     Chris Borkowski {@link http://www.guggenheim.org}
 * @author     Created on 31-August-2009
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );


jimport( 'joomla.application.component.view');
/**
 * HTML View class for the arts_curriculum component
 *
 * @static
 * @package Arts_curriculum
 */
class Arts_curriculumViewVocab_Item extends JView
{
	function display($tpl = null)
	{
		global $mainframe;
		if($this->getLayout() == 'form') {
			$this->_displayForm( $tpl );
			return;
		}
		//get the item
		$item =& $this->get('data');
		parent::display($tpl);
	}
	function _displayForm($tpl)
	{
		global $mainframe, $option;
		$db =& JFactory::getDBO();
		$uri =& JFactory::getURI();
		$user =& JFactory::getUser();
		$model =& $this->getModel( 'vocab_item' );
		$lists = array();
		Arts_curriculumHelper::checkCategories2() ;
		//get the item
		$item =& $this->get('data');
		$isNew = ($item->id < 1);
		// fail if checked out not by 'me'
		if ($model->isCheckedOut( $user->get('id') )) {
			$msg = JText::sprintf( 'DESCBEINGEDITTED', JText::_( 'The list' ), $item->title );
			$mainframe->redirect( 'index.php?option='. $option, $msg );
		}
		// Edit or Create?
		if (!$isNew)
		{
			$model->checkout( $user->get('id') );
		}
		else
		{
			// initialise new record
			$item->published = 1;
			$item->order = 0;
			$item->catid = JRequest::getVar( 'catid', 0, 'post', 'int' );
		}
		// build the html select list for ordering & cat changes
		$query = 'SELECT ordering AS value, title AS text'
		. ' FROM #__arts_curriculum_vocab'
		. ' WHERE catid = ' . (int) $item->catid
		. ' ORDER BY ordering';
		$lists['ordering'] = JHTML::_('list.specificordering', $item, $item->id, $query, 1 );
		$lists['catid'] = JHTML::_('list.category', 'catid', $option, intval( $item->catid ) );
		$lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $item->published );

		//clean item data
		jimport('joomla.filter.output');
		JFilterOutput::objectHTMLSafe( $item, ENT_QUOTES, 'text' );
		$file = JPATH_COMPONENT.DS.'models'.DS.'item.xml';
		$params = new JParameter( $item->params, $file );

		//load the editor
		$editor =& JFactory::getEditor();

		$this->assignRef('editor', $editor);
		$this->assignRef('lists', $lists);
		$this->assignRef('item', $item);
		$this->assignRef('params', $params);
		parent::display($tpl);
	}
}
